package easy;

import java.util.ArrayList;
import java.util.List;

public class Lc257 {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        private List<String> ret = new ArrayList<>();

        public List<String> binaryTreePaths(TreeNode root) {
            dfs(root, "");
            return this.ret;
        }

        void dfs(TreeNode node, String s) {
            if (node == null) {
                return;
            }
            if (node.left == null && node.right == null) {
                ret.add(getString(node, s));
            }
            if (node.left != null) {
                dfs(node.left, getString(node, s));
            }
            if (node.right != null) {
                dfs(node.right, getString(node, s));
            }
        }

        private static String getString(TreeNode node, String s) {
            if (s.isEmpty()) {
                return String.valueOf(node.val);
            }
            return s + "->" + node.val;
        }
    }
}